package algotithm.jianzhioffer.test48;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/13-11:21
 */
public class Solution {

    public static void main(String[] args) {
        String s = "abcabcbb";
        Solution solution = new Solution();
        int length = solution.lengthOfLongestSubstring(s);
        System.out.println(length);
    }

    public int lengthOfLongestSubstring(String s) {
        int[] arr = new int[128];
        char[] ch = s.toCharArray();
        int res = 0;
        for (int i = 0, j = 0; i < ch.length; i++) {
            arr[ch[i]]++;
            while (arr[ch[i]] > 1) {
                arr[ch[j]]--;
                j++;
            }
            res = Math.max(res,i - j + 1 );
        }
        return res;
    }

}
